home *** CD-ROM | disk | FTP | other *** search
- // ⌐ 2005 The Weather Channel Interactive, Inc. All Rights Reserved.
-
- oDataSources.Fcst = function(){};
- oDataSources.Fcst.prototype = new oDataSourcesStub;
-
- function Forecast() {}
- Forecast.inherits(oDataSourcesStub);
- var Fcst = new Forecast();
-
-
- Forecast.prototype.setTooltip = function(panelID, dayIndex, daynight, showIcon, dayDisplayStr){
- try{
- var sIcon = false;
- var sLabel = false;
- switch(showIcon){
- case "icon":
- sIcon = true;
- break;
- case "iconandlabel":
- sIcon = true;
- sLabel = true;
- break;
- case "label":
- sLabel = true;
- break;
- }
-
- var iconIndex = '';
- if(this.Data['days'][dayIndex][daynight + '.t'] != 'N/A'){
- iconIndex = this.Data['days'][dayIndex][daynight + '.icon'];
- }else{
- iconIndex = 'na';
- }
- }catch(e){ }
-
- try{
- // first, we make a tooltip object
- var _tooltip = document.createElement("tooltip");
- _tooltip.setAttribute("id", ToolbarContainers[panelID].getID() + ".Tooltip"); // and give it an id
-
- // now we make an hbox
- var tthbox = document.createElement("hbox");
- _tooltip.appendChild(tthbox);
-
- // now we make a pair of vboxs
- var ttvbox1 = document.createElement("vbox");
- tthbox.appendChild(ttvbox1);
- var ttvbox2 = document.createElement("vbox");
- tthbox.appendChild(ttvbox2);
-
- if(sIcon){
- XULSimple.Image(ttvbox1, "icons/wx/64x64/" + iconIndex + ".png", 64, 64);
- }
-
- if(sLabel){
- var l = new oXUL.Label(ttvbox2, "Forecast Summary:");
- l.Bold();
- l.Make();
-
- XULSimple.Label(ttvbox2, dayDisplayStr + " in " + this.Data['dnam']);
- XULSimple.Label(ttvbox2, this.Data['days'][dayIndex][daynight + '.t']);
- if(daynight == "d"){
- XULSimple.Label(ttvbox2, "High of " + this.Data['days'][dayIndex]['hi'] + Degrees + this.Data['ut']);
- //XULSimple.Label(ttvbox2, "High of " + this.Data['days'][dayIndex]['hi'] + " " + Degrees + this.Data['ut']);
- }else{
- XULSimple.Label(ttvbox2, "Low of " + this.Data['days'][dayIndex]['low'] + Degrees + this.Data['ut']);
- // XULSimple.Label(ttvbox2, "Low of " + this.Data['days'][dayIndex]['low'] + " " + Degrees + this.Data['ut']);
- }
- if(this.Data['days'][dayIndex][daynight + '.wind.t'] == "CALM"){
- XULSimple.Label(ttvbox2, "Winds: CALM");
- }else{
- XULSimple.Label(ttvbox2, "Winds: " + this.Data['days'][dayIndex][daynight + '.wind.t'] + " at " + this.Data['days'][dayIndex][daynight + '.wind.s'] + " " + this.Data['us']);
- }
- XULSimple.Label(ttvbox2, "Precip. Chance: " + this.Data['days'][dayIndex][daynight + '.ppcp'] + "%");
- }
-
- _tooltip.setAttribute("noautohide", false);
- _tooltip.setAttribute("position", "overlap");
- _tooltip.position = "overlap";
-
- _tooltip.setAttribute("noautohide", true);
- _tooltip.setAttribute("position", "before_start");
- _tooltip.setAttribute("align", "center");
- }catch(e){
- debugLog("err in fcst tooltip: " + e);
- }
-
- try{
- var p = document.getElementById(GlobalToolbarLocation);
- var t = document.getElementById(ToolbarContainers[panelID].getID() + ".Tooltip");
- if(p && t)
- p.removeChild(t);
- }
- catch(e){
- debugLog("error removing tooltip: " + this.id + " " + e);
- }
- try{
- document.getElementById(GlobalToolbarLocation).appendChild(_tooltip);
- }catch(e){
- debugLog("error appending tooltip: " + this.id + " " + e);
- }
-
- }
-
- // parse an xml doc into our obs object
- Forecast.prototype.parseFunc = function(xmlDoc){
- var configutil = new ConfigUtils();
- try {
- configutil.convertData(GlobalUserConfig, "Fcst", xmlDoc);
- }catch(e) {
- debugLog('err in fcst conversion: ' + e);
- }
-
- this.oldData = this.Data;
- this.Data = {}; // flush the Data hash
-
- this.parseHeader(xmlDoc);
-
- try{
- // now we move on to the current conditions
- var dayf = xmlDoc.getElementsByTagName("dayf")[0].childNodes;
- var x = 0;
-
- // loop through all the children under the dayf node
- var dayCounter = 0;
- this.Data['days'] = new Array();
- for(x = 0; x < dayf.length; x++){
- if(dayf[x].nodeName == "day"){
- this.Data['days'][dayCounter] = {};
- this.Data['days'][dayCounter]['d'] = dayf[x].getAttribute("d");
- this.Data['days'][dayCounter]['t'] = dayf[x].getAttribute("t");
- this.Data['days'][dayCounter]['dt'] = dayf[x].getAttribute("dt");
-
- var fcstNode = dayf[x].childNodes;
- var y = 0;
-
- for(y = 0; y < fcstNode.length; y++){
- if(fcstNode[y].nodeName == "#text"){
- continue;
- }
-
- if(fcstNode[y].nodeName == "part"){
- var fcstDayNight = fcstNode[y].getAttribute("p");
- var dayPart = fcstNode[y].childNodes;
- var f = 0;
-
- for(f = 0; f < dayPart.length; f++){
- if(dayPart[f].nodeName == "#text"){
- continue;
- }
-
- if((dayPart[f].childNodes.length == 1) && (typeof(dayPart[f].firstChild.nodeValue) == "string")){
- this.Data['days'][dayCounter][fcstDayNight + "." + dayPart[f].nodeName] = dayPart[f].firstChild.nodeValue;
- }else if(dayPart[f].childNodes.length > 1){
- var childName = dayPart[f].nodeName;
- var child = dayPart[f].childNodes;
- var c = 0;
-
- for(c = 0; c < child.length; c++){
- // if this is not a valid node name, skip it
- if(child[c].nodeName == "#text"){
- continue;
- }
-
- // otherwise, make a new entry in this.Data for it
- if(typeof(child[c].firstChild.nodeValue) == "string"){
- this.Data['days'][dayCounter][fcstDayNight + "." + childName + "." + child[c].nodeName] = child[c].firstChild.nodeValue;
- }
- }
- }
- }
- }else if(typeof(fcstNode[y].firstChild.nodeValue) == "string"){
- this.Data['days'][dayCounter][fcstNode[y].nodeName] = fcstNode[y].firstChild.nodeValue;
- }
- }
-
- dayCounter++;
- }
-
- }
- }catch(e){
- // GlobalError.Show();
- debugLog("error parsing fcst data" + e);
- }
-
- this.run++;
- this.setPanel();
- this.Finish();
- }
-
-
- Forecast.prototype.setPanel = function(){
- var daynight = ""; // are we doing the high or low for the forecast
- var nextDay = false; // should we bypass this day...
- var displayPanelType = ""; // what kind of dipsplay type is it for the panel
- var displayTooltip = ""; // is the tooltip enabled
- var displayTooltipType = ""; //what kind of display type is it for the tooltip
-
- debugLog("creating fcst panels in Fcst.setPanel");
-
- // force the max days based on the extended forecast config
- var maxDays = GlobalUserConfig.getAllProfiles().getDefaultProfile().getExtForecast().getExtDetails().getDays();
- if(GlobalUserConfig.getAllProfiles().getDefaultProfile().getExtForecast().getIsEnabled() == "false"){
- maxDays = 0;
- }
-
- var day0Enabled = GlobalUserConfig.getAllProfiles().getDefaultProfile().getForecast().getIsEnabled();
- var afterSwitch = isAfterTimeSwitch(this.Data['tm']);
-
- try{
- for(var day in this.PanelList){
- var panelID = this.PanelList[day];
- var url = '';
- var iconIndex = '';
-
- // ok, this is a bit cheesy but...
- // if we are now on the first extended day and are should show tomorrow as the first forecast
- // after the time switch, drop day 1 and go ahead on to day 2
- if(nextDay){
- day++;
- }
- if((panelID == "Day0") && (day0Enabled == "false")){
- continue;
- }
-
- if(day > maxDays){
- continue;
- }
-
- // ok, if this is the first day, get the normal forecast data
- if(panelID == "Day0"){
- displayPanelType = GlobalUserConfig.getAllProfiles().getDefaultProfile().getForecast().getType();
- displayTooltip = GlobalUserConfig.getAllProfiles().getDefaultProfile().getForecast().getToolTip().getIsEnabled();
- displayTooltipType = GlobalUserConfig.getAllProfiles().getDefaultProfile().getForecast().getToolTip().getType();
- }else{
- displayPanelType = GlobalUserConfig.getAllProfiles().getDefaultProfile().getExtForecast().getType();
- displayTooltip = GlobalUserConfig.getAllProfiles().getDefaultProfile().getExtForecast().getToolTip().getIsEnabled();
- displayTooltipType = GlobalUserConfig.getAllProfiles().getDefaultProfile().getExtForecast().getToolTip().getType();
- }
-
-
- if(GlobalUserConfig.getAllProfiles().getDefaultProfile().getExtForecast().getExtDetails().getTime() == "day"){
- daynight = "d";
- }else{
- daynight = "n";
- }
- // now we make a pair of hboxs
- var panelHbox = document.createElement("hbox");
- panelHbox.setAttribute("context", ToolbarContainers[panelID].getID() + ".Tooltip");
- // try{
- // panelHbox.setAttribute("id", panelID + "HBox");
- // alert(panelHbox.getAttribute("id"));
- // }catch(e) {
- // alert("111" + e);
- // }
-
-
- var panelText = "";
-
- var dayDisplayStr = "";
- // deal with the time forecast switheroo
- var date = new Date();
- // if(((date.getHours() >= 15) && (date.getHours() <= 23)) || (date.getHours() == 0)){
- if(afterSwitch){
- if(panelID == "Day0"){ // ok, we are between time switch and midnight and on the first fcst panel
- if(GlobalUserConfig.getAllProfiles().getDefaultProfile().getForecast().getForecastSwitch() == "tonight"){
- panelText += "Tonight: " + this.Data['days'][day]['low'];
- dayDisplayStr = "Tonight";
- daynight = "n";
- }else{
- day++; // jump forward to the next day
- nextDay = true;
- maxDays++; // make sure we add one more day to the max extended days
- panelText += "Tomorrow: " + this.Data['days'][day]['hi'];
- dayDisplayStr = "Tomorrow";
- }
- }else{
- if(daynight == "d"){
- panelText += DayLookup[this.Data['days'][day]['t']] + ": " + this.Data['days'][day]['hi'];
- }else{
- panelText += DayLookup[this.Data['days'][day]['t']] + ": " + this.Data['days'][day]['low'];
- }
- dayDisplayStr = this.Data['days'][day]['t'];
- }
- }else{
- if(panelID == "Day0"){
- panelText += "Today: " + this.Data['days'][day]['hi'];
- dayDisplayStr = "Today";
- }else{
- if(daynight == "d"){
- panelText += DayLookup[this.Data['days'][day]['t']] + ": " + this.Data['days'][day]['hi'];
- }else{
- panelText += DayLookup[this.Data['days'][day]['t']] + ": " + this.Data['days'][day]['low'];
- }
- dayDisplayStr = this.Data['days'][day]['t'];
- }
- }
- // panelText += " "; // spaces between temperature value and degree character?/
- panelText += Degrees;
- panelText += this.Data['ut'];
- // panelText += ' ' + day + ' ' + panelID;
-
-
- // now we get the link to handle the clicks on the toolbar
- if(day == 0){
- url = this.getLink('localtoday');
- }else{
- url = this.getLink('localext', day);
- }
- panelHbox.setAttribute("uri", url);
- if(this.Data['days'][day][daynight + '.t'] != 'N/A'){
- iconIndex = this.Data['days'][day][daynight + '.icon'];
- }else{
- iconIndex = 'na';
- }
- switch(displayPanelType){
- case 'icon':
- XULSimple.Image(panelHbox, "icons/wx/20x20/" + iconIndex + ".png", 20, 20);
- break;
-
- case 'label':
- XULSimple.Label(panelHbox, panelText);
- break;
-
- case 'iconandlabel':
- XULSimple.Label(panelHbox, panelText);
- XULSimple.Image(panelHbox, "icons/wx/20x20/" + iconIndex + ".png", 20, 20);
- break;
- }
-
- ToolbarContainers[panelID].Show();
- ToolbarContainers[panelID].drawFromHbox(panelHbox);
-
- if(displayTooltip == "true"){
- this.setTooltip(panelID, day, daynight, displayTooltipType, dayDisplayStr);
- }
-
- try{
- if(panelID == "Day0"){
- panelHbox.addEventListener('click',interClickDay0,false);
- } else if(panelID == "Day1") {
- panelHbox.addEventListener('click',interClickDay1,false);
- } else if(panelID == "Day2") {
- panelHbox.addEventListener('click',interClickDay2,false);
- } else if(panelID == "Day3") {
- panelHbox.addEventListener('click',interClickDay3,false);
- } else {
- panelHbox.addEventListener('click',interClickDay4,false);
- }
- //panelHbox.setAttribute("onclick", "openLinkInNewTab('" + url + "');");
- }catch(e) {
- alert("ERROR: " + e);
- }
- }
- }catch(e){
- debug('error setting up fcst panels: ' + e);
- debugLog("error creating fcst panels in Fcst.setPanel " + e);
- }
- }
-
-
-
-
-
-